/*
 * Tulipallo - The Java Finite Volume Method Simulation
 * Copyright (C) 2010 M2 Astronautics
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.
 *
 */

package org.tulipallo.tools.cfd.entity;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * <p/>
 * <tt>Tulipallo - The Java Finite Volume Method Simulation<br />
 * Copyright &copy; 2010 M2 Astronautics</tt>
 * <p/>
 * <tt>This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.</tt>
 * <p/>
 * <tt>You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.</tt>
 *
 * @author Robert R Murrell
 * @since Java 6
 * @version 1.0 beta
 */
public class Memento {
    private final Map<Attribute, Object> values;

    public Memento(final Map<Attribute, Object> values) {
        this.values   = new HashMap(values.size());
        for(Entry<Attribute, Object> entry : values.entrySet()) {
            Attribute attribute = entry.getKey();
            this.values.put(attribute, attribute.getType().clone(entry.getValue()));
        }
    }

    public Map<Attribute, Object> getValues() {
        return Collections.unmodifiableMap(this.values);
    }

    public Object getAttribute(final Attribute attribute) {
        if(attribute == null)
            throw new IllegalArgumentException(
                    "Argument \"attribute\" cannot be null or 0 length.");
        return this.getAttribute(attribute);
    }
    
    public void clear() {
        this.values.clear();
    }
}
